<!---
Copyright: (c) 2006 The MachBlog Authors
Authors: Matt Woodward (mpwoodward@gmail.com) & Peter J. Farrell (pjf@maestropublishing.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.

$Id: AggregatorGateway.cfc 1103 2007-02-26 21:31:19Z mpwoodward $

Notes:
--->
<cfcomponent 
	displayname="AggregatorGateway" 
	output="false" 
	extends="org.machblog.aggregator.AggregatorGateway" 
	hint="AggregatorGateway for MachBlog (MySQL)">
	
	<cffunction name="init" access="public" output="false" returntype="AggregatorGateway" 
			hint="Constructor for this CFC">
		<cfreturn this />
	</cffunction>
	
	<cffunction name="getAggregators" access="public" output="false" returntype="query" 
			hint="Returns a query object containing aggregators based on arguments passed in">
		<cfargument name="getActiveOnly" type="boolean" required="false" default="false" />
		<cfargument name="getAutoPingOnly" type="boolean" required="false" default="false" />
		
		<cfset var getAggregators = "" />
		
		<!--- if we're getting auto-ping only, need to only get active ones --->
		<cfif arguments.getAutoPingOnly>
			<cfset arguments.getActiveOnly = true />
		</cfif>
		
		<cftry>
			<cfquery name="getAggregators" datasource="#getDatasource().getDsn()#" 
					username="#getDatasource().getUserName()#" password="#getDatasource().getPassword()#">
				SELECT 	machblog_aggregator.aggregator_id, 
						machblog_aggregator.aggregator_name, 
						machblog_aggregator.aggregator_description, 
						machblog_aggregator.aggregator_url, 
						machblog_aggregator.ping_url, 
						machblog_aggregator.auto_ping, 
						machblog_aggregator.dt_last_pinged, 
						machblog_aggregator.dt_created, 
						machblog_aggregator.is_active 
				FROM 	machblog_aggregator 
				WHERE 	1 = 1 
				<cfif arguments.getActiveOnly>
				AND 	machblog_aggregator.is_active = <cfqueryparam value="1" cfsqltype="cf_sql_tinyint" /> 
				</cfif>
				<cfif arguments.getAutoPingOnly>
				AND 	machblog_aggregator.auto_ping = <cfqueryparam value="1" cfsqltype="cf_sql_tinyint" /> 
				</cfif>
				ORDER BY aggregator_name ASC
			</cfquery>
			<cfcatch type="database">
				<cfthrow type="application" message="Database Error [databaseerror]" detail="#CFCATCH.Detail#" />
			</cfcatch>
		</cftry>
		
		<cfreturn getAggregators />
	</cffunction>
</cfcomponent>
